﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ProductViewModel>" %>

<%@ Import Namespace="SDT.Lib.Helpers" %>
<%@ Import Namespace="SDT.Lib.Paging" %>
<%@ Import Namespace="SDT.Admin.ViewModels" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Danh sách sản phẩm
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%if (ViewData["MessageInfo"] == null)
      { %>
    <form action="/Product" method="post" name="adminForm" id="adminForm">
    <table width="100%">
        <tr>
            <td align="left">
                Tìm nhanh
                <%= Html.TextBox("Keyword", Model.Keyword) %>
                <%= Html.ActionImageJS("Tìm kiếm", "icon-32-search.png", "document.adminForm.submit();", false)%>
            </td>
            <td align="right">
                <%=Html.DropDownList("TypeID", new SelectList(Model.ProductTypes, "ID", "Name", Model.FilterProductTypeID).ToList(), "-- Đối tượng --", new { onchange="document.adminForm.submit();",style="width:130px"})%>
                <%=Html.DropDownList("CatID", new SelectList(Model.Categories,"ID","Name",Model.FilterCategoryID) , "-- Chuyên mục --", new { onchange = "document.adminForm.submit();" })%>
                <%=Html.DropDownList("HolidayID", new SelectList(Model.ProductHolidays,"ID","Name",Model.FilterProductHolidayID) , "-- Dịp --", new { onchange = "document.adminForm.submit();" })%>
                <%=Html.Hidden("hdAction", string.Empty)%>
            </td>
        </tr>
    </table>
    <table width="100%" class="adminlist">
        <thead>
            <tr>
                <th width="10" align="right">
                    STT
                </th>
                <th width="30">
                </th>
                <th width="30">
                </th>
                <th>
                    <%= Html.Sort("Tên sản phẩm", "Title", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
                <th style="width: 180px">
                    <%= Html.Sort("Thuộc chuyên mục", "CatID", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
                <th style="width: 90px">
                    <%= Html.Sort("Cập nhật", "ModifyDate", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
                <th style="width: 60px; color: #1D60FF;">
                    Xuất bản?
                </th>
                <th style="width: 40px; color: #1D60FF;">
                    Hot?
                </th>
                <th style="width: 40px; color: #1D60FF;">
                    Deal?
                </th>
                <th style="width: 30px">
                    <%= Html.Sort("ID", "ID", ViewData["orderDir"].ToString(), ViewData["order"].ToString())%>
                </th>
                <th style="width: 30px;text-align:center">
                   <%=Html.CheckBox("chkAll", new { onclick = "DoCheckBox(this);" })%>
                </th>
            </tr>
        </thead>
        <tbody>
            <% 
                int i = Model.Products.PageIndex*Model.Products.PageSize;
                foreach (var item in Model.Products)
                {
                    i++;
            %>
            <tr>
                <td align="right">
                    <%= i.ToString() %>
                </td>
                <td align="center">
                    <%= Html.ActionImage("Sửa", "icon-24-edit.png", "Product", "Edit", new Dictionary<string, object>() { { "id", item.ID } })%>
                </td>
                <td align="center">
                    <%= Html.ActionImage("Xóa", "icon-24-delete.png", "Product", "Delete", new Dictionary<string, object>() { { "id", item.ID } })%>
                </td>
                <td>
                    <%= Html.ActionLink(item.Name, "Details", new { id = item.ID })%>                    
                </td>
                <td>
                    <%= Html.Encode(item.ProductCategory.Name)%>                    
                </td>
                <td>
                    <%= Html.Encode(item.ModDate != null ? item.ModDate.Value.ToString("dd/MM/yyyy") : "--")%>
                </td>
                <td align="center">
                    <img alt="" id="imgPubYN_<%= item.ID %>" onclick="ChangePubYN(<%= item.ID %>);" value="<%= item.PubYN %>"
                        src="<%= item.PubYN ? "/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                </td>
                <td align="center">
                    <img alt="" id="imgHotYN_<%= item.ID %>" onclick="ChangeHotYN(<%= item.ID %>);" value="<%= item.HotYN %>"
                        src="<%= item.HotYN ? "/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                </td>
                <td align="center">
                    <img alt="" id="imgDealYN_<%= item.ID %>" onclick="ChangeDealYN(<%= item.ID %>);" value="<%=item.DealYN!=null && item.DealYN==true? "True":"False" %>"
                        src="<%= item.DealYN!=null && item.DealYN==true ? "/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                </td>
                <td>
                    <%= Html.Encode(item.ID) %>
                </td>
                <td style="text-align:center"><%=Html.CheckBox("chk_" + item.ID.ToString())%></td>
            </tr>
            <% } %>
        </tbody>
    </table>
    <%= Html.Hidden("order")%>
    <%= Html.Hidden("orderDir")%>
    <table width="100%">
        <tr>
            <td align="center">
                <div class="pager">
                    <label>
                        Hiển thị #</label>
                    <%
                        int[] pageSizeList = { 1, 5, 10, 15, 20, 25, 50, 100 };
                    %>
                    <%= Html.DropDownList("PageSize", new SelectList(pageSizeList, Model.Products.PageSize), new { onchange = "document.adminForm.submit();" })%>
                    <%= Html.Pager(Model.Products.PageSize, Model.Products.PageNumber, Model.Products.TotalItemCount)%>
                </div>
            </td>
        </tr>
    </table>
    </form>
    <% } %>

    

    <script type="text/javascript">
        function ChangePubYN(id) {
            var obj = $("#imgPubYN_" + id);
            ApplyChangeYN("/AjaxData/UpdateProductPubYN/" + id + '/' + obj.attr("value"), id, obj);
        }
        function ChangeDealYN(id) {
            var obj = $("#imgDealYN_" + id);
            ApplyChangeYN("/AjaxData/UpdateProductDealYN/" + id + '/' + obj.attr("value"), id, obj);
        }
        function ChangeHotYN(id) {
            var obj = $("#imgHotYN_" + id);
            ApplyChangeYN("/AjaxData/UpdateProductHotYN/" + id + '/' + obj.attr("value"), id, obj);
        }
        function ConfirmDeleteAll() {
            var isTrue = ConfirmDelete();
            if (isTrue) {
                ChangeAction('hdAction', 'delete');
                document.getElementById('adminForm').submit();
            }
            return false;
        }
        function UpProduct() {
            ChangeAction('hdAction', 'update');
            document.getElementById('adminForm').submit();
            return false;
        }
    </script>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Toolbar" runat="server">
     <%= Html.Toolbar("Thêm mới", "/Product/Create", "new") %>
     <%= Html.Toolbar("Up tin", "#", "upload", string.Empty, "UpProduct();")%>
	 <%= Html.Toolbar("Xóa tất cả", "#", "delete", string.Empty, "ConfirmDeleteAll();")%>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Header" runat="server">
    Danh sách sản phẩm
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Message" runat="server">
    <%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>
</asp:Content>
